package com.yotoodesign.dianba.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yotoodesign.dianba.R;
import com.yotoodesign.dianba.bean.BaseData;
import com.yotoodesign.dianba.bean.Song;

public class TopSongAdapter extends BaseAdapter {

	private Context     mContext;
	private ArrayList<BaseData> songList;
	
	
	public ArrayList<BaseData> getSongList() {
		return songList;
	}

	public void setSongList(ArrayList<BaseData> songList) {
		this.songList = songList;
	}

	public TopSongAdapter(Context c){
		this.mContext = c;
	}
	
	@Override
	public int getCount() {
		return songList!=null?songList.size():0;
	}

	@Override
	public Object getItem(int position) {
		return songList!=null?songList.get(position):null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		int[] seqs = {R.drawable.top_song_1,R.drawable.top_song_6,
				R.drawable.top_song_2,R.drawable.top_song_7,
				R.drawable.top_song_3,R.drawable.top_song_8,
				R.drawable.top_song_4,R.drawable.top_song_9,
				R.drawable.top_song_5,R.drawable.top_song_10,};
		
		View view = LayoutInflater.from(mContext).inflate(R.layout.top_song_render, null);
		
		Song song = (Song)songList.get(position);
		String sname = song.getName().length()>6?song.getName().substring(0, 6)+"...":song.getName();
		TextView tvSongName = (TextView)view.findViewById(R.id.tvSongName);
		tvSongName.setText(sname);
		
		TextView tvSingerName = (TextView)view.findViewById(R.id.tvSingerName);
		if(song.getSinger()!=null){
			tvSingerName.setText(song.getSinger().getName());
		}
		
		return view;
	}
	

}
